package com.itheima.dao;

import com.github.pagehelper.Page;
import com.itheima.pojo.Setmeal;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

public interface SetmealDao {

    @Insert("insert into t_setmeal (id,name,code,helpCode,sex,age,price,remark,attention,img) " +
            " values(#{id},#{name},#{code},#{helpCode},#{sex},#{age},#{price},#{remark},#{attention},#{img})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    public Integer add(Setmeal setmeal);

    @Insert("insert into t_setmeal_checkgroup (setmeal_id,checkgroup_id) values(#{setmealId},#{checkgroupId})")
    public Integer add_t_setmeal_checkgroup(@Param("setmealId") Integer setmealId,@Param("checkgroupId") Integer checkgroupId);

    @Select("select * from t_setmeal")
    public List<Setmeal> findPage();

    @Select("select * from t_setmeal where name like CONCAT('%',#{queryString},'%') or code like CONCAT('%',#{queryString},'%') or helpCode like CONCAT('%',#{queryString},'%')")
    public Page<Setmeal> findPage1(String queryString);

    // ---------------用户端-----------------
    @Select("select * from  t_setmeal")
    public List<Setmeal> getSetmeal();


    @Select("select id,name,code,helpCode,sex,age,price,remark,attention,img from t_setmeal where id=#{id}")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "name",property = "name"),
            @Result(column = "code",property = "code"),
            @Result(column = "helpCode",property = "helpCode"),
            @Result(column = "sex",property = "sex"),
            @Result(column = "age",property = "age"),
            @Result(column = "price",property = "price"),
            @Result(column = "remark",property = "remark"),
            @Result(column = "attention",property = "attention"),
            @Result(column = "img",property = "img"),
            @Result(column = "id",property = "checkGroups",javaType = java.util.List.class,
            many = @Many(select = "com.itheima.dao.CheckGroupDao.findBySetmealId")),
    })
    public Setmeal findById(Integer id);

    @Select("select s.name name,s.price*count(s.id) value from t_order o,t_setmeal s where o.setmeal_id=s.id and o.orderDate between #{begin} and #{end} and o.orderStatus='已到诊' group by s.name")
    List<Map<String, Object>> findSetmealIncome(Map<String, String> map);
}
